#ifndef __LBEHAVIOUR_H__
#define __LBEHAVIOUR_H__

#include "cocos2d.h"
#include "../CoreMacro.h"


NS_CC_CORE_BEGIN


/*
	This class simulates the behaviour of an object
	You can simulator object behaviour by adding logic control
	on update method.

	Use :
	SomeBehaviour* pBehave = new SomeBehaviour( );

	pMyChar->addChild( pBehave );
*/
class LBehaviour : public CCLayer // It a layer so it can receive touch event
{
public:
	LBehaviour( );
	virtual ~LBehaviour( );

	//Override me :)
	virtual bool		init		( ) ;
	//Override me :)
	virtual void		update		( float dt ) ;

	//If you dont know what you are doing, pls do not override this method
	virtual void		setParent	( CCNode* pParent );

	//By use template you can get the User of this behaviour
	// Use :
	//		...some where on LBehaviour::update() method
	//		CCSprite* pParent = this->getSource<CCSprite>();
	//		pParent->runAction( CCFadeIn::create(1) );
	template<typename T>
	T					getSource	( );

protected:
};



template<typename T>
inline
T LBehaviour::getSource( )
{
	return dynamic_cast<T>(this->getParent());
}

NS_CC_CORE_END



#endif